#! /usr/bin/perl -w
# stdin/args: logfile
# Prints a summary of test results. 

use strict;

my ($totsucc, $tottotal) = (0, 0); # subtests count
my ($tstsucc, $tsttotal) = (0, 0); # tests count

my $fmt   = "%-16s %4d of %4d,  %6.2f%%\n";
my $hdfmt = "%-16s %s\n";
my $separator;

{
    my @headers = ("Test", "successful subtests");
    printf $hdfmt, @headers;
    $separator = sprintf $hdfmt, map({ '-' x length $_ } @headers);
    print $separator;
}

while (<>) {
    if (/^!Summary!([^!]*)!(\d+)!(\d+)$/) {
	my ($testname, $succ, $total) = ($1, $2, $3);

	$totsucc  += $succ;
	$tottotal += $total;

	$tstsucc  += ($succ == $total);
	$tsttotal += 1;

	printf $fmt, $testname, $succ, $total, $succ/$total*100;
    }
}

print $separator;
printf $fmt, 'Tests',    $tstsucc, $tsttotal, $tstsucc/$tsttotal*100;
printf $fmt, 'Subtests', $totsucc, $tottotal, $totsucc/$tottotal*100;
